package Servlet;
 
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import Logic.MemberLogic;
import Model.MemberBean;
 
@SuppressWarnings("serial")
public class MemberServlet extends HttpServlet {	
	 @Override
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {      
		 response.setCharacterEncoding("utf-8");
		 response.setContentType("text/html;charset=utf-8");
		 PrintWriter out = response.getWriter();
		 String opType = request.getParameter("opType");  
		 
	 }
	 
    // 接收客户端浏览器的POST请求，由Service方法跳转
    @Override
	public void doPost(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {
    	response.setCharacterEncoding("utf-8");
		 response.setContentType("text/html;charset=utf-8");
		 PrintWriter out = response.getWriter();
		 String opType = request.getParameter("opType");
		 
		 if (opType.equals("getMember")){//根据会员ID获取会员信息        	        	
			 int MemberID = Integer.parseInt(request .getParameter("ID")); 	            
			 MemberLogic memberlogic = new MemberLogic();
			 List<MemberBean> listMember = memberlogic.getMember(MemberID);				
			 if (listMember!=null){
				 HttpSession session = request.getSession();            	   
				 session.setAttribute("getMember", listMember);
			 }
		 }else if (opType.equals("getMemberByName")){//根据会员姓名获取会员信息        	        	
			 String MemberName = request.getParameter("MemberName"); 	            
			 MemberLogic memberlogic = new MemberLogic();
			 List<MemberBean> listMember = memberlogic.getMemberByName(MemberName);				
			 if (listMember!=null){
				 HttpSession session = request.getSession();            	   
				 session.setAttribute("getMemberByName", listMember);
			 }
		 }else if (opType.equals("addMember")){	//新增会员		 
			 String MemberID = request.getParameter("MemberID");
			 String MemberName = request.getParameter("MemberName");
			 String MemberAddress = request.getParameter("MemberAddress");
			 String MemberOccupation = request.getParameter("MemberOccupation");
 
			 MemberBean memberbean = new MemberBean();
			 memberbean.setID(Integer.parseInt(MemberID));
			 memberbean.setName(MemberName);
			 memberbean.setAddress(MemberAddress);
			 memberbean.setOccupation(MemberOccupation);
			 
			 MemberLogic memberlogic = new MemberLogic();
			 memberlogic.addMember(memberbean);
			 out.print(1);
		 }
    }
        
}

